#include "ui_widget.h"
#include "widget.h"
#include "password_line_edit.h"
#include "event_filter.h"
#include <QLabel>
#include <QLineEdit>
#include <QGridLayout>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    resize(400, 300);
    setFocusPolicy(Qt::StrongFocus);

    QLineEdit *pCommonLineEdit = new QLineEdit(this);
    PasswordLineEdit *pPasswordLineEdit = new PasswordLineEdit(this);
    QLineEdit *pFilterLineEdit = new QLineEdit(this);

    QLabel *pCommonLabel = new QLabel(QStringLiteral("密码框-普通："), this);
    QLabel *pPasswordLabel = new QLabel(QStringLiteral("密码框-事件重写："), this);
    QLabel *pFilterLabel = new QLabel(QStringLiteral("密码框-事件过滤器："), this);

    pFilterLineEdit->installEventFilter(new EventFilter(this));
    pFilterLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
    pFilterLineEdit->setPlaceholderText(QStringLiteral("密码由字母、数字、下划线组成，长度8-16位"));
    pFilterLineEdit->setContextMenuPolicy(Qt::NoContextMenu);
    pFilterLineEdit->setMaxLength(16);

    QGridLayout *pLayout = new QGridLayout();
    pLayout->addWidget(pCommonLabel, 0, 0);
    pLayout->addWidget(pCommonLineEdit, 0, 1);
    pLayout->addWidget(pPasswordLabel, 1, 0);
    pLayout->addWidget(pPasswordLineEdit, 1, 1);
    pLayout->addWidget(pFilterLabel, 2, 0);
    pLayout->addWidget(pFilterLineEdit, 2, 1);
    pLayout->setHorizontalSpacing(10);
    pLayout->setVerticalSpacing(10);
    pLayout->setContentsMargins(10, 10, 10, 10);

    setLayout(pLayout);
}

Widget::~Widget()
{
    delete ui;
}
